//
//  $Id: i2c.h 42 2008-10-04 18:40:36Z jcw $
//  $Revision: 42 $
//  $Author: jcw $
//  $Date: 2008-10-04 14:40:36 -0400 (Sat, 04 Oct 2008) $
//  $HeadURL: http://tinymicros.com/svn_public/arm/lpc2148_demo/trunk/i2c/i2c.h $
//

#ifndef __I2C_IRQ_H
#define __I2C_IRQ_H

#include "_config_cpu_.h"

typedef enum {
  	ACKPOLL_NO = 0,
  	ACKPOLL_YES
} i2c_ack_poll_e;


//  Does not define slave RX statuses.  Bus errors (I2C_STAT == 0) is remapped
//  to I2CERR_ERROR in i2cStatus() so that we can use a value of 0 to indicate 
//  no error.
typedef enum {
  	I2CERR_NONE = 0,
  	I2CERR_BUSY,
  	I2CERR_EMPTY,
  	I2CERR_TIMEOUT,
  	I2CERR_TIMEOUTWC,
  	I2CERR_TIMEOUTACKPOLL,
  	I2CERR_NOTIMPLEMENTED,
  	I2CERR_OTHER,
  	I2CERR_BUSERROR,
  	I2CERR_BUSERRORx       = 0x00,
  	I2CERR_STARTTX         = 0x08,
  	I2CERR_REPEATEDSTARTTX = 0x10,
  	I2CERR_SLAWTX_ACKRX    = 0x18,
  	I2CERR_SLAWTX_NACKRX   = 0x20,
  	I2CERR_DATTX_ACKRX     = 0x28,
  	I2CERR_DATTX_NACKRX    = 0x30,
  	I2CERR_ARBLOST         = 0x38,
  	I2CERR_SLARTX_ACKRX    = 0x40,
  	I2CERR_SLARTX_NACKRX   = 0x48,
  	I2CERR_DATRX_ACKTX     = 0x50,
  	I2CERR_DATRX_NACKTX    = 0x58,
  	I2CERR_NOINFO          = 0xf8
} i2c_err_e;


#if (USE_STRING_MESSAGE == pdON)
typedef struct i2cErrnoStr_s {
  	int errno;
  	const char *text;
} i2c_errno_str_t;

static i2c_errno_str_t i2c_errno_str [] = {
  	{ I2CERR_NONE,              "I2CERR_NONE" },
  	{ I2CERR_BUSY,              "I2CERR_BUSY" },
  	{ I2CERR_EMPTY,             "I2CERR_EMPTY" },
  	{ I2CERR_TIMEOUT,           "I2CERR_TIMEOUT" },
  	{ I2CERR_TIMEOUTWC,         "I2CERR_TIMEOUTWC" },
  	{ I2CERR_TIMEOUTACKPOLL,    "I2CERR_TIMEOUTACKPOLL" },
  	{ I2CERR_NOTIMPLEMENTED,    "I2CERR_NOTIMPLEMENTED" },
  	{ I2CERR_OTHER,             "I2CERR_OTHER" },
  	{ I2CERR_BUSERROR,          "I2CERR_BUSERROR" },
  	{ I2CERR_BUSERRORx,         "I2CERR_BUSERRORx" },
  	{ I2CERR_STARTTX,           "I2CERR_STARTTX" },
  	{ I2CERR_REPEATEDSTARTTX,   "I2CERR_REPEATEDSTARTTX" },
  	{ I2CERR_SLAWTX_ACKRX,      "I2CERR_SLAWTX_ACKRX" },
  	{ I2CERR_SLAWTX_NACKRX,     "I2CERR_SLAWTX_NACKRX" },
  	{ I2CERR_DATTX_ACKRX,       "I2CERR_DATTX_ACKRX" },
  	{ I2CERR_DATTX_NACKRX,      "I2CERR_DATTX_NACKRX" },
  	{ I2CERR_ARBLOST,           "I2CERR_ARBLOST" },
  	{ I2CERR_SLARTX_ACKRX,      "I2CERR_SLARTX_ACKRX" },
  	{ I2CERR_SLARTX_NACKRX,     "I2CERR_SLARTX_NACKRX" },
  	{ I2CERR_DATRX_ACKTX,       "I2CERR_DATRX_ACKTX" },
  	{ I2CERR_DATRX_NACKTX,      "I2CERR_DATRX_NACKTX" },
  	{ I2CERR_NOINFO,            "I2CERR_NOINFO" },
};
#else
typedef struct i2cErrnoStr_s {
  	int errno;
} i2c_errno_str_t;

static i2c_errno_str_t i2c_errno_str [] = {
  	I2CERR_NONE,
  	I2CERR_BUSY,
  	I2CERR_EMPTY,
  	I2CERR_TIMEOUT,
  	I2CERR_TIMEOUTWC,
  	I2CERR_TIMEOUTACKPOLL,
  	I2CERR_NOTIMPLEMENTED,
  	I2CERR_OTHER,
  	I2CERR_BUSERROR,
  	I2CERR_BUSERRORx,
  	I2CERR_STARTTX,
  	I2CERR_REPEATEDSTARTTX,
  	I2CERR_SLAWTX_ACKRX,
  	I2CERR_SLAWTX_NACKRX,
  	I2CERR_DATTX_ACKRX,
  	I2CERR_DATTX_NACKRX,
  	I2CERR_ARBLOST,
  	I2CERR_SLARTX_ACKRX,
  	I2CERR_SLARTX_NACKRX,
  	I2CERR_DATRX_ACKTX,
  	I2CERR_DATRX_NACKTX,
  	I2CERR_NOINFO,
};

#endif

#endif
